home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Sources / FWViewAs.cpp < prev   
Encoding:
Text File  |  1996-04-25  |  9.7 KB  |  346 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWViewAs.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWVIEWAS_H
  13. #include "FWViewAs.h"
  14. #endif
  15.  
  16. #ifndef FWSTDDEF_H
  17. #include "FWStdDef.h"
  18. #endif
  19.  
  20. #ifndef FWCONTXT_H
  21. #include "FWContxt.h"
  22. #endif
  23.  
  24. #ifndef FWPRESEN_H
  25. #include "FWPresen.h"
  26. #endif
  27.  
  28. // ----- OS Layer -----
  29.  
  30. #ifndef FWRECSHP_H
  31. #include "FWRecShp.h"
  32. #endif
  33.  
  34. #ifndef FWPOLY_H
  35. #include "FWPoly.h"
  36. #endif
  37.  
  38. #ifndef FWPOLYSH_H
  39. #include "FWPolySh.h"
  40. #endif
  41.  
  42. #ifndef FWREGION_H
  43. #include "FWRegion.h"
  44. #endif
  45.  
  46. #ifndef FWBMPSHP_H
  47. #include "FWBmpShp.h" 
  48. #endif
  49.  
  50. #ifndef FWCFMRES_H
  51. #include "FWCFMRes.h"
  52. #endif
  53.  
  54. #ifndef FWRECT_H
  55. #include "FWRect.h"
  56. #endif
  57.  
  58. #ifndef FWICONSH_H
  59. #include "FWIconSh.h"
  60. #endif
  61.  
  62. #ifndef FWODGEOM_H
  63. #include "FWODGeom.h"
  64. #endif
  65.  
  66. #ifndef FWLINSHP_H
  67. #include "FWLinShp.h"
  68. #endif
  69.  
  70. // ----- Framework Layer -----
  71.  
  72. #ifndef FWFRAME_H
  73. #include "FWFrame.h"
  74. #endif
  75.  
  76. #ifndef FWPART_H
  77. #include "FWPart.h"
  78. #endif
  79.  
  80. #ifndef FWUTIL_H
  81. #include "FWUtil.h"
  82. #endif
  83.  
  84. // ----- OpenDoc Includes -----
  85.  
  86. #ifndef SOM_ODFacet_xh
  87. #include <Facet.xh>
  88. #endif
  89.  
  90. // ----- Platform Includes -----
  91.  
  92. #if defined(FW_BUILD_MAC) && !defined(__ICONS__)
  93. #include <Icons.h>
  94. #endif
  95.  
  96. //========================================================================================
  97. // RunTime Info
  98. //========================================================================================
  99.  
  100. #ifdef FW_BUILD_MAC
  101. #pragma segment fwpart2
  102. #endif
  103.  
  104. //========================================================================================
  105. // CLASS FW_CViewAs
  106. //========================================================================================
  107.  
  108. //----------------------------------------------------------------------------------------
  109. //    FW_CViewAs::FW_CViewAs
  110. //----------------------------------------------------------------------------------------
  111.  
  112. FW_CViewAs::FW_CViewAs(Environment *ev) :
  113.     fShape(NULL)
  114. {
  115. FW_UNUSED(ev);
  116. }
  117.  
  118. //----------------------------------------------------------------------------------------
  119. //    FW_CViewAs::~FW_CViewAs
  120. //----------------------------------------------------------------------------------------
  121.  
  122. FW_CViewAs::~FW_CViewAs()
  123. {
  124.     delete fShape;
  125.     fShape = NULL;
  126. }
  127.  
  128. //----------------------------------------------------------------------------------------
  129. //    FW_CViewAs::Unload
  130. //----------------------------------------------------------------------------------------
  131.  
  132. void FW_CViewAs::Unload(Environment* ev)
  133. {
  134. FW_UNUSED(ev);
  135.     delete fShape;
  136.     fShape = NULL;
  137. }
  138.  
  139. //========================================================================================
  140. // CLASS FW_CViewAsThumbnail
  141. //========================================================================================
  142.  
  143. //----------------------------------------------------------------------------------------
  144. //    FW_CViewAsThumbnail::FW_CViewAsThumbnail
  145. //----------------------------------------------------------------------------------------
  146.  
  147. FW_CViewAsThumbnail::FW_CViewAsThumbnail(Environment *ev) :
  148.     FW_CViewAs(ev)
  149. {
  150. }
  151.  
  152. //----------------------------------------------------------------------------------------
  153. //    FW_CViewAsThumbnail::~FW_CViewAsThumbnail
  154. //----------------------------------------------------------------------------------------
  155.  
  156. FW_CViewAsThumbnail::~FW_CViewAsThumbnail()
  157. {
  158. }
  159.  
  160. //----------------------------------------------------------------------------------------
  161. //    FW_CViewAsThumbnail::Load
  162. //----------------------------------------------------------------------------------------
  163.  
  164. void FW_CViewAsThumbnail::Load(Environment* ev, FW_CFrame* frame)
  165. {
  166.     if (fShape == NULL)
  167.     {
  168.         fUsedRect.Set(FW_kZeroPoint, FW_IntToFixed(64), FW_IntToFixed(64));
  169.         
  170.         FW_CBitmap bitmap(64, 64, 8);
  171.         
  172.         {
  173.             FW_CBitmapContext bc(ev, bitmap);
  174.             
  175.             FW_CRectShape::RenderRect(bc, fUsedRect, FW_kFill, FW_kWhiteEraseInk);
  176.             FW_CRectShape::RenderRect(bc, fUsedRect, FW_kFrame);
  177.             FW_CLineShape::RenderLine(bc, fUsedRect.TopLeft(), fUsedRect.BotRight());
  178.             FW_CLineShape::RenderLine(bc, fUsedRect.BotLeft(), fUsedRect.TopRight());
  179.             
  180.             frame->BuildThumbnail(ev, bc, fUsedRect);        
  181.         }
  182.         
  183.         fShape = FW_NEW(FW_CBitmapShape, (bitmap, fUsedRect));
  184.     }
  185. }
  186.  
  187. //----------------------------------------------------------------------------------------
  188. //    FW_CViewAsThumbnail::CalcUsedShape
  189. //----------------------------------------------------------------------------------------
  190.  
  191. ODShape* FW_CViewAsThumbnail::CalcUsedShape(Environment* ev) const
  192. {    
  193.     return ::FW_NewODShape(ev, fUsedRect);
  194. }
  195.  
  196. //----------------------------------------------------------------------------------------
  197. //    FW_CViewAsThumbnail::Draw
  198. //----------------------------------------------------------------------------------------
  199.  
  200. void FW_CViewAsThumbnail::Draw(Environment* ev, FW_CFrame* frame, ODFacet* facet, ODShape* invalidShape)
  201. {
  202.     Load(ev, frame);
  203.     
  204.     FW_CFrameContext fc(ev, facet, invalidShape);
  205.     fShape->Render(fc);
  206.     
  207.     if (facet->GetHighlight(ev) != kODNoHighlight)
  208.     {
  209.         FW_CRect bounds = frame->GetVisibleBounds(ev);
  210.         FW_CInk hilite(FW_kRGBBlack, FW_kRGBWhite, FW_kHilite);
  211.         FW_CRectShape::RenderRect(fc, bounds, FW_kFill, hilite);
  212.     }
  213. }
  214.  
  215. //========================================================================================
  216. // CLASS FW_CViewAsIcon
  217. //========================================================================================
  218.  
  219. //----------------------------------------------------------------------------------------
  220. //    FW_CViewAsIcon::FW_CViewAsIcon
  221. //----------------------------------------------------------------------------------------
  222.  
  223. FW_CViewAsIcon::FW_CViewAsIcon(Environment *ev, short iconSize) :
  224.     FW_CViewAs(ev),
  225.     fIconSize(iconSize)
  226. {
  227. }
  228.  
  229. //----------------------------------------------------------------------------------------
  230. //    FW_CViewAsIcon::~FW_CViewAsIcon
  231. //----------------------------------------------------------------------------------------
  232.  
  233. FW_CViewAsIcon::~FW_CViewAsIcon()
  234. {
  235. }
  236.  
  237. //----------------------------------------------------------------------------------------
  238. //    FW_CViewAsIcon::Draw
  239. //----------------------------------------------------------------------------------------
  240. // invalidShape is in Frame Coordinates
  241.  
  242. void FW_CViewAsIcon::Draw(Environment* ev, FW_CFrame* frame, ODFacet* facet, ODShape* invalidShape)
  243. {
  244.     Load(ev, frame);
  245.     
  246.     FW_RenderIconTransform iconTransform = FW_kIconTransformNone;
  247.     
  248.     if (facet->GetHighlight(ev) == kODFullHighlight )
  249.         iconTransform = FW_kIconTransformSelected;
  250.     
  251.     // Check to see if the frame has been opened into a part window.
  252.     FW_CWindow* window = frame->GetPresentation(ev)->GetPartWindow(ev);
  253.     if (window && window->IsShown(ev) )
  254.         iconTransform |= FW_kIconTransformOpen;
  255.     
  256.     ((FW_CIconShape*)fShape)->SetIconTransform(iconTransform);
  257.     
  258.     FW_CFrameContext fc(ev, facet, invalidShape);
  259.     fShape->Render(fc);
  260. }
  261.  
  262. //----------------------------------------------------------------------------------------
  263. //    FW_CViewAsIcon::Load
  264. //----------------------------------------------------------------------------------------
  265.  
  266. void FW_CViewAsIcon::Load(Environment* ev, FW_CFrame* frame)
  267. {
  268.     if (fShape == NULL)
  269.     {
  270.         FW_CIcon icon = frame->GetIcon(ev, fIconSize);    
  271.     
  272.         FW_CRect iconRect(FW_kZeroPoint, FW_IntToFixed(fIconSize), FW_IntToFixed(fIconSize));
  273.         fShape = FW_NEW(FW_CIconShape, (icon, iconRect));
  274.     }
  275. }
  276.  
  277. //----------------------------------------------------------------------------------------
  278. //    FW_CViewAsIcon::CalcUsedShape
  279. //----------------------------------------------------------------------------------------
  280.  
  281. ODShape* FW_CViewAsIcon::CalcUsedShape(Environment* ev) const
  282. {
  283.     FW_ASSERT(fShape != NULL);
  284.     
  285. #ifdef FW_BUILD_MAC
  286.     FW_CIcon icon;
  287.     FW_RenderIconAlignment alignment;
  288.     FW_RenderIconTransform transform;
  289.     FW_CRect rect;
  290.     ((FW_CIconShape*)fShape)->GetGeometry(icon, rect, transform, alignment);
  291.     
  292.     RgnHandle rgn = ::NewRgn();
  293.     FW_CPlatformRect bounds(0, 0, fIconSize, fIconSize);
  294.     ::IconSuiteToRgn(rgn, &bounds, atNone, icon.GetPlatformIcon());
  295.     
  296.     return ::FW_NewODShape(ev, rgn);
  297. #endif
  298.  
  299. #ifdef FW_BUILD_WIN
  300.     FW_DEBUG_MESSAGE("Not yet implemented");
  301. #endif
  302. }
  303.  
  304. //========================================================================================
  305. // CLASS FW_CViewAsSmallIcon
  306. //========================================================================================
  307.  
  308. //----------------------------------------------------------------------------------------
  309. //    FW_CViewAsSmallIcon::FW_CViewAsSmallIcon
  310. //----------------------------------------------------------------------------------------
  311.  
  312. FW_CViewAsSmallIcon::FW_CViewAsSmallIcon(Environment *ev) :
  313.     FW_CViewAsIcon(ev, 16)
  314. {
  315. }
  316.  
  317. //----------------------------------------------------------------------------------------
  318. //    FW_CViewAsSmallIcon::~FW_CViewAsSmallIcon
  319. //----------------------------------------------------------------------------------------
  320.  
  321. FW_CViewAsSmallIcon::~FW_CViewAsSmallIcon()
  322. {
  323. }
  324.  
  325. //========================================================================================
  326. // CLASS FW_CViewAsLargeIcon
  327. //========================================================================================
  328.  
  329. //----------------------------------------------------------------------------------------
  330. //    FW_CViewAsLargeIcon::FW_CViewAsLargeIcon
  331. //----------------------------------------------------------------------------------------
  332.  
  333. FW_CViewAsLargeIcon::FW_CViewAsLargeIcon(Environment *ev) :
  334.     FW_CViewAsIcon(ev, 32)
  335. {
  336. }
  337.  
  338. //----------------------------------------------------------------------------------------
  339. //    FW_CViewAsLargeIcon::~FW_CViewAsLargeIcon
  340. //----------------------------------------------------------------------------------------
  341.  
  342. FW_CViewAsLargeIcon::~FW_CViewAsLargeIcon()
  343. {
  344. }
  345.  
  346.